 package com.gmrz.uaf.crypto.internal.keyFormats;
 
 import com.gmrz.uaf.crypto.CryptoConstants;

 import java.math.BigInteger;
import java.security.GeneralSecurityException;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.RSAPublicKeySpec;
import java.util.Arrays;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
 
 public class UAFAlgKeyRSA2048PSSRaw extends UAFKeyFmt
 {
   private static final Logger LOG = LogManager.getLogger(UAFAlgKeyRSA2048PSSRaw.class);
 
   public UAFAlgKeyRSA2048PSSRaw()
   {
     super(CryptoConstants.UAFAlgkey.UAF_ALG_KEY_RSA_2048_PSS_RAW);
   }
 
   public PublicKey getKey(byte[] pubKey, int algoSuite)
     throws GeneralSecurityException
   {
     KeyFactory factory = KeyFactory.getInstance(this.uafAlgKey.getKeyAlgo());
 
     if (pubKey.length <= 256)
     {
       throw new GeneralSecurityException("Invalid key length - " + pubKey.length);
     }
 
     BigInteger n = new BigInteger(1, Arrays.copyOfRange(pubKey, 0, 256));
 
     BigInteger e = new BigInteger(1, Arrays.copyOfRange(pubKey, 256, pubKey.length));
     byte[] nba = n.toByteArray();
     byte[] eba = e.toByteArray();
     LOG.debug("Decoded N({}) - {}", Integer.valueOf(nba.length), Arrays.toString(nba));
     LOG.debug("Decoded E({}) - {}", Integer.valueOf(eba.length), Arrays.toString(eba));
     RSAPublicKeySpec spec = new RSAPublicKeySpec(n, e);
     RSAPublicKey pub = (RSAPublicKey)factory.generatePublic(spec);
     return pub;
   }
 }
